<template>
  <div class="grade-list">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>成绩查询</span>
        </div>
      </template>

      <el-table :data="gradeList" style="width: 100%">
        <el-table-column prop="examName" label="考试名称" />
        <el-table-column prop="subject" label="科目" />
        <el-table-column prop="score" label="分数" />
        <el-table-column prop="examTime" label="考试时间" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button 
              type="primary" 
              link
              @click="viewDetail(scope.row.id)"
            >
              查看详情
            </el-button>
            <el-button 
              type="warning" 
              link
              @click="submitAppeal(scope.row.id)"
              :disabled="!canAppeal(scope.row)"
            >
              成绩申诉
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 模拟成绩数据
const gradeList = ref([
  {
    id: 1,
    examName: '期中考试',
    subject: '数学',
    score: 85,
    examTime: '2024-04-10',
    canAppeal: true
  },
  {
    id: 2,
    examName: '月考',
    subject: '英语',
    score: 92,
    examTime: '2024-04-15',
    canAppeal: false
  }
])

// 查看详情
const viewDetail = (id) => {
  router.push(`/student/results/${id}`)
}

// 提交申诉
const submitAppeal = (id) => {
  router.push({
    path: '/student/grade-appeal',
    query: { examId: id }
  })
}

// 检查是否可以申诉
const canAppeal = (grade) => {
  return grade.canAppeal
}
</script>

<style scoped>
.grade-list {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 